import { createSlice } from "@reduxjs/toolkit";

const authSlice = createSlice({
  name: "auth",
  initialState: {
    token: "",
    user: {},
  },
  reducers: {
    setToken: (state, { payload }) => {
      localStorage.setItem("TOKEN", JSON.stringify(payload));
      state.token = payload;
    },
    setUser: (state, { payload }) => {
      localStorage.setItem("USER", JSON.stringify(payload));
      state.user = payload;
    },
  },
});

export const { setToken, setUser } = authSlice.actions;
export default authSlice.reducer;
